<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <title>习题 12: 提示别人</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="this is youanan's wiki, design by vimwiki">
    <meta name="author" content="youanan">
    <link rel="shortcut icon" href="../../favicon.ico">

    <!-- Bootstrap core CSS -->
    <link href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css" type="text/css" rel="stylesheet">
    <!--local Bootstrap core CSS -->
    <link href="../../bootstrap/3.3.2/css/bootstrap.min.css" type="text/css" rel="stylesheet">


    <!--local google-code-prettify.CSS -->
    <link href="../../css/prettify.css" type="text/css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../../css/starter-template.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="http://youanan.com">youanan</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="../../index.html">Home</a></li>
            <li><a href="../../diary/diary.html">Diary</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>

    <div class="container">

      <div class="starter-template">
        


<h1 id="toc_1">习题 12: 提示别人</h1>

<p>
当你键入 raw_input() 的时候，你需要键入 ( 和 ) 也就是“括号(parenthesis)”。这和你格式化输出两个以上变量时的情况有点类似，比如说 "%s %s" % (x, y) 里边就有括号。对于 raw_input 而言，你还可以让它显示出一个提示，从而告诉别人应该输入什么东西。你可以在 () 之间放入一个你想要作为提示的字符串，如下所示：
</p>

<pre>
y = raw_input("Name? ")
</pre>

<p>
这句话会用 “Name?” 提示用户，然后将用户输入的结果赋值给变量 y。这就是我们提问用户并且得到答案的方式。
</p>

<p>
也就是说，我们的上一个练习可以使用 raw_input 重写一次。所有的提示都可以通过
raw_input 实现。
</p>

<pre>
age = raw_input("How old are you? ")
height = raw_input("How tall are you? ")
weight = raw_input("How much do you weigh? ")

print "So, you're %r old, %r tall and %r heavy." % (
    age, height, weight)
</pre>

<h2 id="toc_1.1">你应该看到的结果</h2>

<pre>
$ python ex12.py
How old are you? 35
How tall are you? 6'2"
How much do you weight? 180lbs
So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
$
</pre>

<h2 id="toc_1.2">加分习题</h2>

<ol>
<li>
在命令行界面下运行你的程序，然后在命令行输入 pydoc raw_input 看它说了些什么。如果你用的是 Window，那就试一下 python -m pydoc raw_input 。

<li>
输入 q 退出 pydoc。

<li>
上网找一下 pydoc 命令是用来做什么的。

<li>
使用 pydoc 再看一下 open, file, os, 和 sys 的含义。看不懂没关系，只要通读一下，记下你觉得有意思的点就行了。

</ol>

        
      </div>
        <nav>
            <ul class="pagination">
                <li><a href="intro_zh.html">译者前言</a></li>
                <li><a href="intro.html">前言</a></li>
                <li><a href="ex1.html">1</a></li>
                <li><a href="ex2.html">2</a></li>
                <li><a href="ex3.html">3</a></li>
                <li><a href="ex4.html">4</a></li>
                <li><a href="ex5.html">5</a></li>
                <li><a href="ex6.html">6</a></li>
                <li><a href="ex7.html">7</a></li>
                <li><a href="ex8.html">8</a></li>
                <li><a href="ex9.html">9</a></li>
                <li><a href="ex10.html">10</a></li>
                <li><a href="ex11.html">11</a></li>
                <li><a href="ex12.html">12</a></li>
                <li><a href="ex13.html">13</a></li>
                <li><a href="ex14.html#">14</a></li>
                <li><a href="ex15.html#">15</a></li>
                <li><a href="ex16.html#">16</a></li>
                <li><a href="ex17.html#">17</a></li>
                <li><a href="ex18.html#">18</a></li>
                <li><a href="ex19.html#">19</a></li>
                <li><a href="ex20.html#">20</a></li>
                <li><a href="ex21.html#">21</a></li>
                <li><a href="ex22.html#">22</a></li>
                <li><a href="ex23.html#">23</a></li>
                <li><a href="ex24.html#">24</a></li>
                <li><a href="ex25.html#">25</a></li>
                <li><a href="ex26.html#">26</a></li>
                <li><a href="ex27.html#">27</a></li>
                <li><a href="ex28.html#">28</a></li>
                <li><a href="ex29.html#">29</a></li>
                <li><a href="ex30.html#">30</a></li>
                <li><a href="ex31.html#">31</a></li>
                <li><a href="ex32.html#">32</a></li>
                <li><a href="ex33.html#">33</a></li>
                <li><a href="ex34.html#">34</a></li>
                <li><a href="ex35.html#">35</a></li>
                <li><a href="ex36.html#">36</a></li>
                <li><a href="ex37.html#">37</a></li>
                <li><a href="ex38.html#">38</a></li>
                <li><a href="ex39.html#">39</a></li>
                <li><a href="ex40.html#">40</a></li>
                <li><a href="ex41.html#">41</a></li>
                <li><a href="ex42.html#">42</a></li>
                <li><a href="ex43.html#">43</a></li>
                <li><a href="ex44.html#">44</a></li>
                <li><a href="ex45.html#">45</a></li>
                <li><a href="ex46.html#">46</a></li>
                <li><a href="ex47.html#">47</a></li>
                <li><a href="ex48.html#">48</a></li>
                <li><a href="ex49.html">49</a></li>
                <li><a href="ex50.html">50</a></li>
                <li><a href="ex51.html">51</a></li>
                <li><a href="ex52.html">52</a></li>
                <li><a href="next.html">下一步</a></li>
                <li><a href="advice.html">老程序员的建议</a></li>
                </li>
            </ul>
        </nav>
      <footer>
          <p>&copy; Company 2015  <img src="http://youanan.qiniudn.com/youanan.com/youananemail.png"  alt="联系我" border="0"></p>
      </footer>

    </div><!-- /.container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="../../jquery/1.11.2/jquery.min.js"></script>
    <!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> -->
    <script type="text/javascript" src="http://cdn.bootcss.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../bootstrap/3.3.2/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../js/panel/python_panel.js"></script>
    <script type="text/javascript" src="../../js/google-code-prettify/prettify.js"></script>
  </body>
</html>

